﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T.FAS.Runtime.Metadata.UnitTest
{
    public class RedisHelper
    {
        private Process processRedis;
        public void StartRedis()
        {
            processRedis = new Process();
            processRedis.StartInfo.UseShellExecute = true;
            processRedis.StartInfo.WorkingDirectory = System.Environment.CurrentDirectory + @"\Redis";
            processRedis.StartInfo.FileName = "Start Service.bat";
            processRedis.Start();

            System.Threading.Thread.Sleep(1000);
        }

        public void CloseRedis()
        {
            try
            {
                if (processRedis != null)
                    processRedis.CloseMainWindow();
            }
            catch { }

            Process[] ps1 = Process.GetProcessesByName("redis-server");
            if (ps1 != null)
            {
                try
                {
                    foreach (var item in ps1)
                    {
                        try
                        {
                            item.CloseMainWindow();
                            item.Kill();
                        }
                        catch
                        { }
                    }
                }
                catch
                { }
            }

        }
    }
}
